package hikari.hcomponents.physics;

import com.gooddies.wiring.Wiring;
import hikari.gui.panels.bullet.BulletBoxRigidBodyPanel;
import hikari.gui.panels.bullet.IBulletRigidBodyEditPanel;
import hikari.persistence.file.FileSection;
import java.io.IOException;
import org.swig.jirr.ISceneNode;
import org.swig.jirr.vector3df;

/**
 * @author sad
 */
public class BoxRigidBody extends IRigidBody {

    protected vector3df size;
    protected PhysicsData data;

    public BoxRigidBody(ISceneNode node, PhysicsData data) {
        this.data = data;
        size = node.getTransformedBoundingBox().getExtent().dividedOperator(2.f);
    }

    @Override
    public IBulletRigidBodyEditPanel getEditPanel() {
        BulletBoxRigidBodyPanel editPanel = Wiring.getComponent(BulletBoxRigidBodyPanel.class);
        editPanel.init(data);
        return editPanel;
    }

    public vector3df getSize() {
        return size;
    }

    public void setSize(vector3df size) {
        this.size = size;
    }

    @Override
    public void write(FileSection section) throws IOException {
        FileSection sect = section.createNewSection("boxRigid");
        sect.writeVector("size", size);
        sect.close();
    }

    @Override
    public void read(FileSection section) throws IOException {
        size = section.readVector("size");
    }
}